Skip to content

CORS-4425: gcp: add OS image validation for sovereign clouds#10709

Open
barbacbd wants to merge 1 commit into
openshift:mainfrom
barbacbd:CORS-4425
Open

CORS-4425: gcp: add OS image validation for sovereign clouds#10709
barbacbd wants to merge 1 commit into
openshift:mainfrom
barbacbd:CORS-4425

Conversation

@barbacbd

@barbacbd barbacbd commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Sovereign cloud environments (identified by a domain-scoped project ID containing ":") require an OS image to be specified. This adds install-config validation ensuring that each compute and control plane machine pool has an OS image configured, either directly or via the default machine platform.

Summary by CodeRabbit

  • New Features
    • Added additional validation for GCP sovereign cloud environments to require a complete machine pool OS image (including both image name and project).
    • The check is applied only for the sovereign cloud case.
  • Bug Fixes
    • GCP machine pool validation now surfaces clear, field-specific errors for missing OS image details in sovereign configurations.
  • Tests
    • Added table-driven test coverage for sovereign vs non-sovereign behavior and OS image error aggregation.

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jul 23, 2026
@openshift-ci-robot

openshift-ci-robot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

@barbacbd: This pull request references CORS-4425 which is a valid jira issue.

Details

In response to this:

Sovereign cloud environments (identified by a domain-scoped project ID containing ":") require an OS image to be specified. This adds install-config validation ensuring that each compute and control plane machine pool has an OS image configured, either directly or via the default machine platform.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: d9c357da-adfc-4283-9492-1c8b4ee3019d

📥 Commits

Reviewing files that changed from the base of the PR and between 27ebe8d and 2b14c79.

📒 Files selected for processing (3)
  • pkg/types/gcp/validation/machinepool.go
  • pkg/types/gcp/validation/machinepool_test.go
  • pkg/types/validation/machinepools.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • pkg/types/gcp/validation/machinepool.go
  • pkg/types/gcp/validation/machinepool_test.go

📝 Walkthrough

Walkthrough

Changes

Sovereign OS image validation

Layer / File(s) Summary
OS image validation rule and coverage
pkg/types/gcp/validation/machinepool.go, pkg/types/gcp/validation/machinepool_test.go
Adds sovereign-cloud validation requiring a machine pool OS image with non-empty name and project fields, with table-driven coverage for skipped, valid, and invalid cases.
Machine pool validation integration
pkg/types/validation/machinepools.go
Appends sovereign OS image validation errors to the existing GCP machine pool validation results.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 15
✅ Passed checks (15 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding GCP OS image validation for sovereign cloud environments.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed The added test names are static t.Run labels; no Ginkgo titles or dynamic/generated values appear in the changed files.
Test Structure And Quality ✅ Passed PASS: The new table-driven unit test has one behavior per case, no cluster resources or waits, and matches existing testify-based validation tests; no setup/cleanup concerns.
Microshift Test Compatibility ✅ Passed No new Ginkgo e2e tests were added; the touched test is a standard Go unit test and references no MicroShift-unsupported APIs.
Single Node Openshift (Sno) Test Compatibility ✅ Passed Only validation code and unit tests changed; no new Ginkgo e2e tests or SNO-unsafe multi-node assumptions were added.
Topology-Aware Scheduling Compatibility ✅ Passed Only GCP install-config validation changed; no pod specs, controllers, nodeSelectors, affinity, or topology-based scheduling logic were added.
Ote Binary Stdout Contract ✅ Passed No process-level stdout writes were added; the PR only changes validation code and t.Run-based tests, with no main/init/TestMain/RunSpecs hooks in touched files.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed No new Ginkgo e2e tests were added; this PR only adds validation code and a standard Go unit test, with no IPv4 or external connectivity assumptions.
No-Weak-Crypto ✅ Passed Changed code only adds GCP OS-image validation and tests; no weak crypto primitives, custom crypto, or secret/token comparisons were introduced.
Container-Privileges ✅ Passed Only GCP validation Go code and tests changed; no container/K8s manifests or privilege-related fields (privileged, hostPID, hostNetwork, hostIPC, allowPrivilegeEscalation, SYS_ADMIN, root) were added.
No-Sensitive-Data-In-Logs ✅ Passed No new logging was added in the touched files; the PR only adds validation errors, not log output exposing secrets or PII.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions
The command is terminated due to an error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions


Comment @coderabbitai help to get the list of available commands.

@openshift-ci
openshift-ci Bot requested review from jhixson74 and rochacbruno July 23, 2026 19:23

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/types/gcp/validation/machinepool_test.go`:
- Around line 73-80: Update the table-driven test around
ValidateOSImageForSovereignCloud to retain the field.ErrorList instead of only
converting it to an aggregate error, then assert that invalid cases report the
expected test-path.osImage field path, including nested name or project paths
where applicable. Keep the existing valid-case no-error assertion.

In `@pkg/types/gcp/validation/machinepool.go`:
- Around line 91-92: Update the validation logic surrounding the osImage check
in machine-pool validation so a non-nil but incomplete image reports missing
fields at osImage.name and/or osImage.project, while retaining the parent
osImage required error only when the image object is nil. Ensure each error path
matches the user-facing YAML/JSON structure and remains actionable.
- Around line 90-92: Update the OS image validation condition in the machine
pool validation flow to treat a non-nil pool.OSImage as the selected override,
validating its Name and Project without falling back to
platform.DefaultMachinePlatform.OSImage. Consult the default image only when
pool.OSImage is nil, and add a regression test covering an incomplete pool image
with a complete default image.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 27d610fa-2339-4fda-ae5a-853a08259a24

📥 Commits

Reviewing files that changed from the base of the PR and between 15956c8 and 460d487.

📒 Files selected for processing (3)
  • pkg/types/gcp/validation/machinepool.go
  • pkg/types/gcp/validation/machinepool_test.go
  • pkg/types/validation/machinepools.go

Comment thread pkg/types/gcp/validation/machinepool_test.go
Comment thread pkg/types/gcp/validation/machinepool.go Outdated
Comment thread pkg/types/gcp/validation/machinepool.go
Comment thread pkg/types/gcp/validation/machinepool.go Outdated
func ValidateOSImageForSovereignCloud(platform *gcp.Platform, pool *gcp.MachinePool, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}

if !strings.Contains(platform.ProjectID, ":") {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can re-use an existing func, right?

// GetCloudEnvironment determines the cloud environment from the project ID format.
// Returns CloudEnvironmentSovereign for sovereign cloud environments, empty string for public GCP.
// Uses known sovereign cloud project ID prefixes to distinguish from organization-scoped
// public GCP projects (orgname:project-id).
func GetCloudEnvironment(projectID string) string {

Comment thread pkg/types/gcp/validation/machinepool.go Outdated
}

func hasValidOSImage(pool *gcp.MachinePool) bool {
return pool != nil && pool.OSImage != nil && pool.OSImage.Name != "" && pool.OSImage.Project != ""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 We should validate and report individual missing fields to make it clearer for users, similar to what coderrabit recommended: #10709 (comment). How about?

if pool == nil || pool.OSImage == nil {
	allErrs = append(allErrs, field.Required(fldPath.Child("osImage"),
		"must specify an OS image for sovereign cloud environments (domain-scoped project ID)"))
	return allErrs
}

osImagePath := fldPath.Child("osImage")
if pool.OSImage.Name == "" {
	allErrs = append(allErrs, field.Required(osImagePath.Child("name"),
		"must specify an OS image name for sovereign cloud environments"))
}
if pool.OSImage.Project == "" {
	allErrs = append(allErrs, field.Required(osImagePath.Child("project"),
		"must specify an OS image project for sovereign cloud environments"))
}

Comment thread pkg/types/gcp/validation/machinepool.go Outdated
return allErrs
}

if !hasValidOSImage(pool) && !hasValidOSImage(platform.DefaultMachinePlatform) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, by this point, the pools would already merge with platform.defaultMachinePlatform, so we don't have to check it.

gcpdefaults.Apply(platform.GCP.DefaultMachinePlatform, p.Platform.GCP)
gcpdefaults.SetMachinePoolDefaults(platform, p.Platform.GCP)

Comment thread pkg/types/gcp/validation/machinepool_test.go
Comment thread pkg/types/validation/machinepools.go Outdated
allErrs = append(allErrs, gcpvalidation.ValidateMachinePool(platform.GCP, p.GCP, f)...)
allErrs = append(allErrs, gcpvalidation.ValidateMasterDiskType(pool, f)...)
allErrs = append(allErrs, gcpvalidation.ValidateServiceAccount(platform.GCP, pool, f)...)
allErrs = append(allErrs, gcpvalidation.ValidateOSImageForSovereignCloud(platform.GCP, p.GCP, f)...)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this line is only called if the pool defines a non-nil platform.gcp field, according to:

if p.GCP != nil {
validate(gcp.Name, p.GCP, func(f *field.Path) field.ErrorList { return validateGCPMachinePool(platform, p, pool, f) })
}

That said, a minimal install-config.yaml like below will skip the validation completely.

compute:
- architecture: amd64
  hyperthreading: Enabled
  name: worker
  platform: {}
  replicas: 3
controlPlane:
  architecture: amd64
  hyperthreading: Enabled
  name: master
  platform: {}
  replicas: 3
platform:
  gcp:
    projectID: "eu0::project"

How about running the osImage validation as long as the install platform is GCP? This matches the AWS AMI validation pattern.

if platform.GCP != nil {
	allErrs = append(allErrs, gcpvalidation.ValidateOSImageForSovereignCloud(platform.GCP, p.GCP, fldPath.Child("gcp"))...)
}
if p.GCP != nil {
	validate(gcp.Name, p.GCP, func(f *field.Path) field.ErrorList { return validateGCPMachinePool(platform, p, pool, f) })
}

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/types/validation/machinepools.go`:
- Around line 165-167: Update the GCP validation call in the machine-pool
platform validation flow to pass fldPath.Child("gcp") instead of appending the
duplicate "platform" segment. Add an integration test that verifies the
resulting validation error path matches the YAML/JSON structure, such as
...platform.gcp.osImage.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 5e8908d2-9062-4f5d-9006-c43df1a3346a

📥 Commits

Reviewing files that changed from the base of the PR and between 460d487 and 27ebe8d.

📒 Files selected for processing (3)
  • pkg/types/gcp/validation/machinepool.go
  • pkg/types/gcp/validation/machinepool_test.go
  • pkg/types/validation/machinepools.go

Comment thread pkg/types/validation/machinepools.go
@patrickdillon

Copy link
Copy Markdown
Contributor

/test e2e-gcd-ovn-private-techpreview

@patrickdillon

Copy link
Copy Markdown
Contributor

/approve

@openshift-ci

openshift-ci Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: patrickdillon

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 24, 2026
Sovereign cloud environments (identified by a domain-scoped project ID
containing ":") require an OS image to be specified. This adds
install-config validation ensuring that each compute and control plane
machine pool has an OS image configured, either directly or via the
default machine platform.

@tthvo tthvo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Jul 24, 2026
@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Scheduling required tests:
/test e2e-azure-nat-gateway-single-zone

Scheduling tests matching the pipeline_run_if_changed or not excluded by pipeline_skip_if_only_changed parameters:
/test e2e-gcp-custom-dns
/test e2e-gcp-custom-endpoints
/test e2e-gcp-default-config
/test e2e-gcp-ovn
/test e2e-gcp-ovn-byo-vpc
/test e2e-gcp-ovn-xpn
/test e2e-gcp-secureboot
/test e2e-gcp-xpn-custom-dns
/test e2e-gcp-xpn-dedicated-dns-project
/test e2e-aws-ovn

@openshift-ci

openshift-ci Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

@barbacbd: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-gcp-custom-endpoints 2b14c79 link false /test e2e-gcp-custom-endpoints
ci/prow/e2e-gcp-ovn-byo-vpc 2b14c79 link false /test e2e-gcp-ovn-byo-vpc
ci/prow/e2e-aws-ovn 2b14c79 link true /test e2e-aws-ovn
ci/prow/e2e-azure-nat-gateway-single-zone 2b14c79 link true /test e2e-azure-nat-gateway-single-zone
ci/prow/e2e-gcp-ovn 2b14c79 link true /test e2e-gcp-ovn
ci/prow/e2e-gcp-custom-dns 2b14c79 link false /test e2e-gcp-custom-dns
ci/prow/e2e-gcp-xpn-dedicated-dns-project 2b14c79 link false /test e2e-gcp-xpn-dedicated-dns-project
ci/prow/gcp-custom-endpoints-proxy-wif 2b14c79 link false /test gcp-custom-endpoints-proxy-wif
ci/prow/e2e-gcp-ovn-xpn 2b14c79 link false /test e2e-gcp-ovn-xpn
ci/prow/e2e-gcp-xpn-custom-dns 2b14c79 link false /test e2e-gcp-xpn-custom-dns

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants